<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
    $(function () {
        //校对
        $("#copiedBtn").on('click', function () {
            var ordersStatus = '6';
            updateStatus(ordersStatus);
        })
        //执行
        $("#performBtn").on('click', function () {
            var ordersStatus = '3';
            updateStatus(ordersStatus);
        })
        //驳回
        $("#rebuteBtn").on('click', function () {
            var ordersStatus = '7';
            updateStatus(ordersStatus);
        })
        //修改医嘱状态
        function updateStatus(ordersStatus) {
            var ordersIds = getSelectOrderIds(ordersStatus);//以逗号分隔
            if (ordersIds.length > 1) {
                return delLoad("nurseIndexDiv", '${ctx}/orders/orders/delete?id=' + ordersIds + "&orderStatus=" + ordersStatus, '${ctx}/orders/orders/findNurseOrders?patientId=' + $('#patientId').val() + "&visitId=" + $('#visitId').val()+"&pageFlag=1");
            }
        }


        /**
         *
         * @param ordersStatus
         * @returns {string}
         */
        function getSelectOrderIds(ordersStatus) {
            var parentOrders = $("#contentTable input[name=ordersId]:checked");
            if (parentOrders.length == 0) {
                toastr.error("请先选择一条医嘱！");
                return "";
            }
            var ordersId = "";
            parentOrders.each(function () {
                if (ordersStatus == '6' && $(this).val().split(',')[1] != "1") {
                    toastr.error("请选择未校对的医嘱");
                    return "";
                }
                if (ordersStatus == '3' && $(this).val().split(',')[1] != "0") {
                    toastr.error("请选择临时未执行的医嘱");
                    return "";
                }
                if (ordersStatus == '7' && $(this).val().split(',')[1] != "1") {
                    toastr.error("请选择未校对的医嘱");
                    return "";
                }
                ordersId = ordersId + $(this).val().split(',')[0] + ",";
            });
            ordersId = ordersId.substring(0, ordersId.length - 1);
            return ordersId;
        }
        //全选事件
        $("#all").on('click', function () {
            var isChecked = $(this).prop("checked");
            $("input[name='ordersId']").prop("checked", isChecked);
        })
        $("#contentTable").treeTable({expandLevel:10});
    })
    
    function nurseOrdersPrint() {
        var bedNo = $("#bedNo").val();
        var visitId = $("#visitId").val();
        var patientId = $("#patientId").val();
        var repeatIncaditor = $("#repeatIncaditor").val();
        var orderStatus = $("#orderStatus").val();
        if (repeatIncaditor!=null&&repeatIncaditor!=''){
            printPdf('${ctx}/orders/orders/findNurseOrdersPrint', 'patientId=' + patientId+'&visitId='+visitId+'&repeatIncaditor='+repeatIncaditor+'&bedNo='+bedNo+'&orderStatus='+orderStatus);
        }else {
            toastr.error("请先选择要打印的临时医嘱或者长期医嘱！");
        }
    }
</script>
<div class="app">
<section class="layout">
<section class="main-content col-lg-12" id="LeftDiv">
<div class="content-wrap">
<div class="wrapper" style="bottom: 50px;">
    <ul class="nav nav-tabs">
        <li><a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/nurse/index')">床位列表</a></li>
        <li class="active"><a href="#">医嘱信息</a></li>
    </ul>
    <section class="panel panel-default">
        <div class="panel-body">
            <div class="table-responsive no-border">
                <form:form data-parsley-validate="" modelAttribute="patVisit">
                    <div class="form-group">
                        <label class="col-sm-1 control-label">床位号：</label>

                        <div class="col-sm-2">
                            <form:input path="bedRec.bedNo" id="bedNo" htmlEscape="false" class="form-control" maxlength="200"
                                        disabled="true"/>
                        </div>
                        <label class="col-sm-1 control-label">姓名：</label>

                        <div class="col-sm-2">
                            <form:input path="patVisitIndex.name" htmlEscape="false" class="form-control"
                                        maxlength="200" disabled="true"/>
                        </div>
                        <label class="col-sm-1 control-label">性别：</label>

                        <div class="col-sm-2">
                            <form:input path="patVisitIndex.sex" htmlEscape="false" class="form-control" maxlength="200"
                                        disabled="true" value="${fns:getDictLabel(patVisit.patVisitIndex.sex, 'SEX_DICT', '')}"/>


                        </div>
                        <label class="col-sm-1 control-label">年龄：</label>

                        <div class="col-sm-2">
                            <form:input path="patVisitIndex.age" htmlEscape="false" class="form-control" maxlength="200"
                                        disabled="true"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label">预交金：</label>

                        <div class="col-sm-2">
                            <form:input path="prepayments" htmlEscape="false" class="form-control" maxlength="200"
                                        disabled="true"/>
                        </div>
                        <label class="col-sm-1 control-label">费别：</label>

                        <div class="col-sm-2">
                            <form:input path="patVisitIndex.chargeType" htmlEscape="false" class="form-control"
                                        maxlength="200" disabled="true" value="${fns:getDictLabel(patVisit.patVisitIndex.chargeType, 'CHARGE_TYPE_DICT', '')}"/>
                        </div>
                        <label class="col-sm-1 control-label">诊断：</label>

                        <div class="col-sm-2">
                            <form:input path="diagnosis" htmlEscape="false" class="form-control" maxlength="200"
                                        disabled="true"/>
                        </div>
                        <label class="col-sm-1 control-label">主任医生：</label>

                        <div class="col-sm-2">
                            <form:input path="directorDoctor" htmlEscape="false" class="form-control" maxlength="200"
                                        disabled="true" value="${fns:getUserName(patVisit.directorDoctor)}"/>
                        </div>
                    </div>
                </form:form>
                <div class="datatable-top">
                    <div class="pull-left">
                        <form:form id="searchForm" modelAttribute="orders"
                                   onsubmit="return loadDivForm('nurseIndexDiv','searchForm','${ctx}/orders/orders/findNurseOrders');"
                                   method="post" class="form-inline">
                            <form:hidden path="patientId" id="patientId"/>
                            <form:hidden path="visitId" id="visitId"/>
                            <form:hidden path="pageFlag" value="1"/>
                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                            <input id="pageSize" name="pageSize" type="hidden"
                                   value="${page.pageSize}"/>

                            <form:select path="repeatIncaditor" id="repeatIncaditor" itemLabel="label" itemValue="value"
                                         class="form-control" data-parsley-required="true">
                                <form:option value="" label="全部"/>
                                <form:option value="0" label="临时"/>
                                <form:option value="1" label="长期"/>
                            </form:select>
                            <form:select path="orderStatus" itemLabel="label" itemValue="value" id="orderStatus" class="form-control" data-parsley-required="true">
                                <form:option value="" label="医嘱状态"/>
                                <%--<form:option value="0" label="新开"/>--%>
                                <%--<form:option value="1"  label="传输"/>--%>
                                <form:option value="2" label="转抄"/>
                                <form:option value="3" label="临时执行"/>
                                <form:option value="4" label="停止"/>
                                <form:option value="6" label="执行"/>
                                <form:option value="7" label="护士驳回"/>
                                <form:option value="7" label="护士驳回"/>
                                <form:option value="8" label="医生停止"/>
                            </form:select>

                            <input name="startTime" id="startDate" value="${orders.startTime}"
                                   class="form-control Wdate" type="text"
                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                    />
                            <label>至</label>
                            <input name="endTime" value="${orders.endTime}" class="form-control Wdate"
                                   type="text"
                                   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>

                            <input name="date" id="week" class="btn btn-default" type="button" value="一周内" onclick="dateCondition('week',-7,'startDate')"/>
                            <input name="date" id="halfMonth" class="btn btn-default" type="button" value="半月内" onclick="dateCondition('halfMonth',-15,'startDate')"/>
                            <input name="date"  id="month" class="btn btn-default" type="button" value="一个月内" onclick="dateCondition('month',-30,'startDate')"/>
                            &nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
                            <input id="copiedBtn" class="btn btn-primary" type="button" value="校对"/>
                            <input id="performBtn" class="btn btn-primary" type="button" value="执行"/>
                            <input id="rebuteBtn" class="btn btn-primary" type="button" value="驳回"/>
                            <input id="print" class="btn btn-primary" type="button" onclick="nurseOrdersPrint()" value="打印"/>
                        </form:form>
                    </div>
                </div>

                <table id="contentTable" class="table table-bordered mg-t datatable" checkbox="true">
                    <thead>
                    <tr>
                        <th><input type=checkbox id="all"></th>
                        <th>操作</th>
                        <th>下达时间</th>
                        <th>医嘱内容</th>
                        <th>长期</th>
                        <th>状态</th>
                        <th>类别</th>
                        <th>途径</th>
                        <th>频次</th>
                        <th>执行时间</th>
                        <th>单次用量</th>
                        <th>规格</th>
                        <th>药品厂商</th>
                        <th>执行科室</th>
                        <th>医生说明</th>
                        <th>医生停止时间</th>
                        <th>床号</th>
                        <th>姓名</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${page.list}" var="orders" varStatus="ss">
                        <tr id="${orders.id}">
                            <td>
                                <input type=checkbox name="ordersId"
                                       value="${orders.id},${orders.abledperformFlag}"></td>
                            <td>
                                <c:if test="${!empty orders.doth}">
                                    <font color="red">${orders.doth}</font>
                                </c:if>
                            </td>
                            <td><fmt:formatDate value="${orders.createDate}"  pattern="MM-dd HH:mm"/></td>
                            <td> ${orders.orderText}</td>
                            <td> ${orders.repeatIncaditorTran}</td>
                            <td> ${orders.orderStatusTran}</td>
                            <td> ${orders.isDrugTran}</td>
                            <td> ${fns:getSysDictLabel(orders.administration, 'ADMINISTRATION_DICT', '')}</td>
                            <td> ${orders.freqDesc}</td>
                            <td> ${orders.nursePerformTime}</td>
                            <td>
                                <c:if test="${orders.isDrugTran=='药品'}">
                                    ${orders.singleDose}(${orders.doseUnits})
                                </c:if>
                            </td>
                            <td> ${orders.drugSpec}</td>
                            <td> ${orders.firmId}</td>
                            <td> ${fns:getDeptName(orders.performedBy,'')} </td>
                            <td> ${orders.doctInstruction}</td>
                            <td><fmt:formatDate value="${orders.stopInDate}"  pattern="MM-dd HH:mm"/></td>
                            <td> ${orders.bedNo}</td>
                            <td> ${orders.name}</td>
                        </tr>
                        <c:if test="${orders.children.size()>0}">
                            <c:forEach items="${orders.children}" var="child" varStatus="ss">
                                <tr id='${ss.count}' pId='${orders.id}' style="text-align: center;">
                                    <td></td>
                                    <td></td>
                                    <td><fmt:formatDate value="${child.createDate}"  pattern="MM-dd HH:mm"/></td>
                                    <td> ${child.orderText}</td>
                                    <td> ${child.repeatIncaditorTran}</td>
                                    <td> ${child.orderStatusTran}</td>
                                    <td> ${child.isDrugTran}</td>
                                    <td> ${fns:getSysDictLabel(orders.administration, 'ADMINISTRATION_DICT', '')}</td>
                                    <td> ${orders.freqDesc}</td>
                                    <td> ${child.nursePerformTime}</td>
                                    <td>
                                        <c:if test="${child.isDrugTran=='药品'}">
                                            ${child.singleDose}(${child.doseUnits})
                                        </c:if></td>
                                    <td> ${child.drugSpec}</td>
                                    <td> ${child.firmId}</td>
                                    <td> ${fns:getDeptName(child.performedBy,'')} </td>
                                    <td> ${child.doctInstruction}</td>
                                    <td><fmt:formatDate value="${child.stopInDate}"  pattern="MM-dd HH:mm"/></td>
                                    <td> ${child.bedNo}</td>
                                    <td> ${child.name}</td>
                                </tr>
                            </c:forEach>
                        </c:if>
                    </c:forEach>
                    </tbody>
                </table>
                <div class="pagination">${page}</div>
            </div>
        </div>
    </section>
</div>
</div>
</section>
</section>

</div>

